package com.bright.hxj.cwduijie.service.impl;

import com.bright.hxj.cwduijie.enums.DataApi;
import com.bright.hxj.cwduijie.pojo.bo.ApiDataCollection;
import com.bright.hxj.cwduijie.pojo.po.CustomAssetCode;
import com.bright.hxj.cwduijie.pojo.query.DuijieQuery;
import com.bright.hxj.cwduijie.repository.CustomAssetCodeRepository;
import com.bright.hxj.cwduijie.service.AbstractPerThousandApiService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.function.Function;

/**
 * @Author hxj
 * @Date 2024/7/29 14:43
 * @Description
 */

@Component
@RequiredArgsConstructor
@Slf4j
public class ApiCustomAssetCodeServiceImpl extends AbstractPerThousandApiService<CustomAssetCode> {

    private final CustomAssetCodeRepository repo;

    @Override
    public JpaSpecificationExecutor getJpaSpecificationExecutor() {
        return repo;
    }

    @Override
    public DataApi getDataApi() {
        return DataApi.CUSTOM_ASSET_CODE;
    }

    @Override
    public Function<CustomAssetCode, Integer> getIdFunc() {
        return CustomAssetCode::getID;
    }

    @Override
    protected void getData(ApiDataCollection apiDataCollection, DuijieQuery duijieQuery) {
//        List<CustomAssetCode> all = repo.findAll(getDataQuerySpecification(OpType.ADD_OR_EDIT.getValue(), duijieQuery.getCreditCode()));
        apiDataCollection.setCustomAssetCodes(getNeedDuijieData(duijieQuery));
    }

    @Override
    public Function<CustomAssetCode, String> getDataKeyFunc() {
        return CustomAssetCode::getDATA_KEY;
    }

    @Override
    public Function<ApiDataCollection, List<CustomAssetCode>> getDataFunc() {
        return ApiDataCollection::getCustomAssetCodes;
    }

//    @Override
//    protected List<CustomAssetCode> getNeedDeleteData(DuijieQuery duijieQuery) {
//        return repo.findAll(getDataQuerySpecification(OpType.DEL.getValue(), duijieQuery.getCreditCode()));
//    }

    @Override
    public DataApi getDeleteDataApi() {
        return DataApi.DELETE_CUSTOM_ASSET_CODE;
    }

}
